<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
    <meta charset="UTF-8"/>
    <title>
        index page
    </title>
    <link rel="stylesheet" type="text/css" th:href="@{/static/js/bootstrap4/css/bootstrap.min.css}"/>
    <script th:src="@{/static/js/LodopFuncs.js}"></script>
    <object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width="0" height="0">
        <embed id="LODOP_EM" type="application/x-print-lodop" width="0" height="0" pluginspage="/static/lodop/install_lodop32.exe">
        </embed>
    </object>
</head>
<body>

<div style = "margin-top: 10px; margin-left:10px; argin-buttom:20px">
    <input id = "button" type="button" value="点击保存页面的内容"  onClick = "testPrintSave()"></input>
    <br></br>
    <br></br>
    <input id = "button6" type="button" value="点击测试打印-非浏览器-LodopFuncs.js"  onClick = "print()"></input>
    <br></br>
    <iframe id ="testIframe" style="text-align:center;margin-left: 10px;margin-top:10px"
            src = "/testPrint-native" width='900' height='800'></iframe>
</div>
<textarea rows="15"  cols="80" style="display: none;" id="textarea011">
<table border="1" width="360" height="220" style="border-collapse:collapse; border:solid 1px" bordercolor="#000000">
  <tr>
    <td width="100%" height="240">

      <font face="隶书" size="5" style="letter-spacing: 10px">郭德强</font>
      <p align="center"><font face="宋体" size="3">科学家</font></p>
      <p align="left"><font face="宋体" size="3">　地址：中国北京社会科学院附近东大街西胡同</font></p>
      <p align="left"><font face="宋体" size="3">　电话：010-88811888</font></p>
      <br></br>      　

    </td>
  </tr>
</table>
</textarea>
</body>
<script  type="text/javascript" src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
    /*<![CDATA[ */
    var ctxPath = "";
    //存储
    function testPrintSave(){
        var htDoc = document.getElementById('testIframe').contentWindow.document;
        var setparam = htDoc.getElementsByClassName("setparam");
        for(var i=0;i<setparam.length;i++){
            setparam[i].setAttribute("value",setparam[i].value);
        }
        alert("保存成功！");
        /* var c = htDoc.documentElement.outerHTML;
        var printer = document.getElementById("testIframe").contentWindow;
        printer.document.body.innerHTML = c;
        printer.print();

        setTimeout(function(){
            var htDoc22 = document.getElementById('testIframe').contentWindow.document;
            console.log("点击打印按钮后的延时方法执行 ");
            htDoc22.getElementById('restore-listener').click();
        },500); */
    }

    var LODOP; //声明为全局变量
    //页面下载打印
    function print() {
        var htm =document.getElementById("testIframe").value;
        var url1='/testPrint-native';
        var url= '/testPrint';
        $.ajax({
            url: url,
            data: {id: 1},
            success: function (rsData) {
                LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
                var missionName = "打印任务名111";
                var htDoc = document.getElementById('testIframe').contentWindow.document;
                var printinfo = "";
                printinfo = htDoc.documentElement.outerHTML;
                alert("任务："+missionName+"-"+printinfo);
                LODOP.PRINT_INIT(missionName); //首先一个初始化语句
                //LODOP.ADD_PRINT_HTM(10,55,"100%","100%",document.getElementById("textarea011").value);
                LODOP.ADD_PRINT_HTM(0,0,"100%","100%",printinfo);
                //LODOP.ADD_PRINT_URL(0,0,"100%","100%",url1);//然后多个ADD语句及SET语句
                //LODOP.SET_SHOW_MODE("MESSAGE_PARSING_URL","");//该语句隐藏进度条或修改提示信息
                LODOP.PREVIEW();
                //LODOP.PRINT();                               //最后一个打印(或预览、维护、设计)语句

            }
        });
    }

    /*]]>*/
</script>
<script th:src="@{/static/js/bootstrap4/js/jquery-1.12.4.js}"></script>
<script th:src="@{/static/js/bootstrap4/js/bootstrap.min.js}"></script>
</html>